<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    String imgSrc = basePath + "resources/images/noImage.jpg";
    session.setAttribute("imgSrc", imgSrc);
%>
<!DOCTYPE html>
<html style="background-color: #fff;">
<head>
    <%@include file="../../../../resources/inc/head.jsp" %>
    <!--MiniUI-->
    <link href="<%=basePath%>resources/lib/miniui/themes/default/miniui.css" rel="stylesheet" type="text/css" />
    <script src="<%=basePath%>resources/lib/miniui/miniui.js" type="text/javascript"></script>
    <script src="http://www.miniui.com/demo/pagertree/pagertree.js"></script>
</head>
<body>
<expect-x:tip tipMessage="标识“*”的选项为必填项，其余为选填项。;请按提示信息填写每一个字段" widthClass="full-width-85"/>

<div class="layui-form common-form" lay-filter="layuiadmin-form-contentFriendlyLink"
     id="layuiadmin-form-contentFriendlyLink"
     style="padding: 20px;">

    <div class="layui-form-item">
        <label class="layui-form-label">url</label>
        <div class="layui-input-inline">
            <input type="hidden" name="id" value="${contentActivities.id}">
            <input type="text" name="url" lay-verify="required" value="${contentActivities.url}"
                   placeholder="请输入url" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">产品</label>
        <div class="layui-input-inline">

            <input id="lookup2" name="productId" class="mini-lookup" style="width:100%;height: 500px"
                   textField="productName" valueField="id" popupWidth="auto"
                   popup="#gridPanel" grid="#datagrid1" multiSelect="false" value="${contentActivities.productId}" text="${contentActivities.productName}"
            />

            <div id="gridPanel" class="mini-panel" title="header" iconCls="icon-add" style="width:450px;height:250px;"
                 showToolbar="true" showCloseButton="true" showHeader="false" bodyStyle="padding:0" borderStyle="border:0"
            >
                <div property="toolbar" style="padding:5px;padding-left:8px;text-align:center;">
                    <div style="float:left;padding-bottom:2px;">
                        <span>产品名/Sn码：</span>
                        <input id="keyText" class="mini-textbox" style="width:160px;" onenter="onSearchClick"/>
                        <a class="mini-button" onclick="onSearchClick">查询</a>
                        <a class="mini-button" onclick="onClearClick">清除</a>
                    </div>
                    <div style="float:right;padding-bottom:2px;">
                        <a class="mini-button" onclick="onCloseClick">关闭</a>
                    </div>
                    <div style="clear:both;"></div>
                </div>
                <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;"
                     borderStyle="border:0" showPageSize="true" showPageIndex="true"
                     url="<%=basePath%>manager/content/activities/projectList.html"
                >
                    <div property="columns">
                        <div type="checkcolumn" ></div>
                        <div field="productSn" width="120" headerAlign="center" allowSort="true">Sn码</div>
                        <div field="productName" width="120" headerAlign="center" allowSort="true">产品名称</div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-tab-item layui-show">
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="LAY-submit" id="LAY-submit" value="确认">
        </div>
    </div>

<%@include file="../../../../resources/inc/footer.jsp" %>

<script>
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        var $ = layui.$
            , form = layui.form
    })

    function createSubmit() {
        var layer = layui.layer;
        var submitID = 'LAY-submit';
        layui.form.on('submit(' + submitID + ')', function (data) {
            var formData = data.field;
            var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
            var objExp=new RegExp(Expression);
            if(objExp.test(formData.url) != true){
                layer.msg("请输入正确的url地址");
                return;
            }
            if (formData.id == "" || formData.id == null) {
                delete formData["id"];
                $.ajax({
                    url: '<%=basePath%>manager/content/activities/create.html',
                    type: "POST",
                    data: formData,
                    dataType: "JSON",
                    success: function (data) {
                        layer.closeAll('loading');
                        if (data.success) {
                            layer.msg("创建成功,1秒后跳转")
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            }, 1000);
                        } else {
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            } else {
                $.ajax({
                    url: "<%=basePath%>manager/content/activities/update/" + formData.id + ".html",
                    type: "POST",
                    data: formData,
                    dataType: "JSON",
                    success: function (data) {
                        layer.closeAll('loading');
                        if (data.success) {
                            layer.msg("修改成功,1秒后跳转");
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            }, 1000);
                        } else {
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            }
        })
        $("#" + submitID).trigger('click');
    }


    mini.parse();
    var grid = mini.get("datagrid1");
    var keyText = mini.get("keyText");

    grid.load();

    function onSearchClick(e) {
        grid.load({
            key: keyText.value
        });
    }
    function onCloseClick(e) {
        var lookup2 = mini.get("lookup2");
        lookup2.hidePopup();
    }
    function onClearClick(e) {
        var lookup2 = mini.get("lookup2");
        lookup2.deselectAll();
    }
</script>
</body>
</html>
